import request from "./request";

/**
 * 分页获取博客
 * @param {*} page 当前页码
 * @param {*} limit 页容量
 * @param {*} categoryId 所属分类
 * @returns
 */
  return await request.get("/api/blog", {
    params: {
      page,
      limit,
      categoryId,
    },
  });
}

// 获取博客分类
export async function getBlogCategories() {
  return await request.get("/api/blogtype");
}

// 获取单个博客
export async function getBlog(id) {
  return await request.get(`/api/blog/${id}`);
}

/**
 * 提交评论
 * @param {*} commentInfo { nickname: "xxx", content: "xxxx", blogId: xxx } => 昵称,评论内容,评论的博客id
 * @returns
 */
export async function postComment(commentInfo) {
  return await request.post("/api/comment", commentInfo);
}
// 获取评论
export async function getComments(blogId, page = 1, limit = 10) {
  return await request.get("/api/comment", {
    params: {
      blogId,
      page,
      limit,
    },
  });
}
